﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace A2DFramework.HttpLoadBalancer.Parsers.ConcreteParsers
{
    class HttpHeaderParser : IHttpHeaderParser
    {
        public HttpProtocal.HttpHeaderEntity Parse(string rawHeaderRow)
        {
            if (string.IsNullOrEmpty(rawHeaderRow))
                return new HttpProtocal.HttpHeaderEntity();

            int splitIndex = -1;
            splitIndex = rawHeaderRow.IndexOf(":");
            if (splitIndex <= 0)
                throw new Exception("HttpHeaderParser");

            string key = rawHeaderRow.Substring(0, splitIndex);
            string value = rawHeaderRow.Substring(splitIndex + 1);

            return new HttpProtocal.HttpHeaderEntity() { Key = key.Trim(), Value = value.Trim() };
        }
    }
}
